home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / samba-common.postinst < prev    next >
Encoding:
Text File  |  2009-10-01  |  4.4 KB  |  157 lines

  1. #!/bin/sh
  2. #
  3. #
  4.  
  5. set -e
  6.  
  7. if [ "$1" = "configure" ]
  8. then
  9.     update-alternatives --install /usr/bin/nmblookup nmblookup /usr/bin/nmblookup.samba3 0 \
  10.         --slave /usr/share/man/man1/nmblookup.1.gz nmblookup.1.gz /usr/share/man/man1/nmblookup.samba3.1.gz
  11.     update-alternatives --install /usr/bin/net net /usr/bin/net.samba3 10 \
  12.         --slave /usr/share/man/man8/net.8.gz net.8.gz /usr/share/man/man8/net.samba3.8.gz
  13.     update-alternatives --install /usr/bin/testparm testparm /usr/bin/testparm.samba3 10 \
  14.         --slave /usr/share/man/man1/testparm.1.gz testparm.1.gz /usr/share/man/man1/testparm.samba3.1.gz
  15.     for N in valid.dat upcase.dat lowcase.dat
  16.     do
  17.         update-alternatives --install /usr/share/samba/$N $N /usr/share/samba/$N.samba3 0
  18.     done
  19.     update-alternatives --install /usr/share/samba/panic-action samba-panic-action /usr/share/samba/panic-action.samba3 0
  20. fi
  21.  
  22. # Do debconf stuff here
  23. . /usr/share/debconf/confmodule
  24.  
  25. TEMPDIR=/var/run/samba/upgrades
  26. NEWFILE=$TEMPDIR/smb.conf
  27. CONFIG=/etc/samba/smb.conf
  28.  
  29. # ------------------------- Debconf questions start ---------------------
  30.  
  31. configure_smb_conf() {
  32.     local CONFIG
  33.     CONFIG="$1"
  34.  
  35.     # Is the user configuring with debconf, or he/she prefers
  36.     # swat/manual config?
  37.     db_get samba-common/do_debconf || true
  38.     if [ "${RET}" != "true" ]; then
  39.         return 0
  40.     fi
  41.  
  42.     # Get workgroup name
  43.     db_get samba-common/workgroup || true
  44.     WORKGROUP="${RET}"
  45.  
  46.     # Oh my GOD, this is ugly.  Why would anyone put these
  47.     # characters in a workgroup name?  Why, Lord, why???
  48.     WORKGROUP=`echo $WORKGROUP | \
  49.                sed -e's/\\\\/\\\\\\\\/g
  50.                       s#/#\\\\/#g
  51.                       s/&/\\\&/g
  52.                       s/\\\$/\\\\\\\$/g'`
  53.  
  54.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  55.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  56.             s/^\([[:space:]]*\)workgroup[[:space:]]*=.*/\1workgroup = ${WORKGROUP}/i" \
  57.         "$CONFIG"
  58.  
  59.     # Encrypt passwords?
  60.     db_get samba-common/encrypt_passwords || true
  61.     ENCRYPT_PASSWORDS="${RET}"
  62.  
  63.     sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  64.         /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  65.                 s/^\([[:space:]]*\)encrypt passwords[[:space:]]*=.*/\1encrypt passwords = ${ENCRYPT_PASSWORDS}/i" \
  66.         "$CONFIG"
  67.  
  68.     # Install DHCP support
  69.     db_get samba-common/dhcp
  70.     if [ "$RET" = true ] && \
  71.        ! grep -q dhcp.conf "$CONFIG"
  72.     then
  73.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  74.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ {
  75.                 /wins server[[:space:]]*=/a \\
  76. \\
  77. # If we receive WINS server info from DHCP, override the options above. \\
  78.    include = /etc/samba/dhcp.conf
  79. }" "$CONFIG"
  80.     elif [ "$RET" != true ]; then
  81.         sed -i -e '
  82.         /^#[[:space:]]*If we receive WINS server info from DHCP, override the options above/d
  83.         /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/,/[^[:space:]]/ {
  84.             /^#*[[:space:]]*include[[:space:]]*=[[:space:]]*\/etc\/samba\/dhcp.conf/d
  85.             /^[[:space:]]*$/d
  86.         }' "$CONFIG"
  87.     fi
  88.  
  89.     if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.23b-2 \
  90.        && grep -qi "^[[:space:]]*passdb backend[[:space:]]*=.*guest" "$CONFIG"
  91.     then
  92.         sed -i -e "s/^\([[:space:]]*\)\[global\]/\1\[global\]/i
  93.             /^[[:space:]]*\[global\]/,/^[[:space:]]*\[/ \
  94.                     s/^\([[:space:]]*passdb backend[[:space:]]*=[^,]*\),\?[[:space:]]*guest[[:space:]]*$/\1/i" \
  95.             "$CONFIG"
  96.     fi
  97. }
  98.  
  99.  
  100. if [ -e "$CONFIG" ]; then
  101.     configure_smb_conf "$CONFIG"
  102. fi
  103.  
  104. mkdir -p "$TEMPDIR"
  105.  
  106. if [ -n "$2" ] && dpkg --compare-versions "$2" lt 3.0.28-3; then
  107.     if dpkg --compare-versions "$2" lt 3.0.26a-1 && [ "$2" != "${2%ubuntu*}" ]
  108.     then
  109.         base=dapper
  110.     elif [ "$2" != "${2%ubuntu*}" ]
  111.     then
  112.         base=gutsy
  113.     else
  114.         base=etch
  115.     fi
  116.  
  117.     TEMPLATE=/usr/share/samba/smb.conf.${base}
  118.  
  119.     cp "$TEMPLATE" "$NEWFILE"
  120.     configure_smb_conf "$NEWFILE"
  121.  
  122.     if [ -e "$CONFIG" ]; then
  123.         sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  124.             1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  125.         ' "$CONFIG" >> "$NEWFILE"
  126.     fi
  127.  
  128.     ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  129. fi
  130.  
  131. cp /usr/share/samba/smb.conf "$NEWFILE"
  132. configure_smb_conf "$NEWFILE"
  133.  
  134. if [ -e "$CONFIG" ]; then
  135.     sed -e '1,/^[;#[:space:]]*\[cdrom\]/ { d }
  136.         1,/^[[:space:]]*\[/ { /^[^[]/d; /^$/d }
  137.     ' "$CONFIG" >> "$NEWFILE"
  138. fi
  139.  
  140. ucf --three-way --debconf-ok "$NEWFILE" "$CONFIG"
  141.  
  142. if [ ! -e "$CONFIG" ]; then
  143.     echo "Install/upgrade will fail. To recover, please try:"
  144.     echo "  sudo cp /usr/share/samba/smb.conf $CONFIG"
  145.     echo "  sudo dpkg --configure -a"
  146.     exit 1
  147. else
  148.     ucfr samba-common "$CONFIG"
  149.     chmod a+r "$CONFIG"
  150. fi
  151.  
  152. # ------------------------- Debconf questions end ---------------------
  153.  
  154. db_stop
  155.  
  156.  
  157.